package interfaces;

import gestores.GestorInterfaces;

import java.io.IOException;

import cliente.Cliente;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class EcranLogout extends VBox{
	
	private Cliente cliente;
	private Stage stage;
	private GestorInterfaces interfaces;
	
	public EcranLogout(Stage stage, Cliente cliente, GestorInterfaces interfaces) {
		this.stage = stage;
		this.cliente = cliente;
		this.interfaces = interfaces;
		criarJanelaLogut();
	}
	
	public void criarJanelaLogut() {
		FXMLLoader guest = new FXMLLoader(getClass().getResource("LogOut.fxml"));
		guest.setRoot(this);
		guest.setController(this);

		try {
			guest.load();
		} catch (IOException exception) {
			//TODO
			throw new RuntimeException(exception);
		}
	}

	@FXML
	public void cancelarLogOut(ActionEvent event) {
		stage.close();
	}

	@FXML
	public void aceitarLogOut(ActionEvent event) {
		stage.close();
		interfaces.getStageActual().close();
		cliente.start(new Stage());
	}
}